﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using Skynet.Framework.Common;
using AutoRegisterManager.Common;
using System.Threading;

namespace AutoRegisterManager
{
    public partial class FrmInMoney : Form
    {
        public DataSet cardSavingData;
        public int sum = 0;//读入钱数

        public FrmInMoney()
        {
            InitializeComponent();
            //axTTDriverMgr1.SetLogPath(Application.StartupPath + "\\LogFile\\money.log", 6);
        }


        private void lblClose_Click(object sender, EventArgs e)
        {
            this.icMsg1.timer1.Stop();
            this.timer1.Stop();
            this.DialogResult = DialogResult.Cancel;
        }
        //确认
        private void lblOK_Click(object sender, EventArgs e)
        {
            this.timer1.Stop();
            try
            {
                backgroundWorker2.RunWorkerAsync();
            }
            catch (Exception ex)
            {
                SkynetMessage.MsgInfo(ex.Message);
                return;
            }
            //调用充值业务
        }
       
        private void FrmInMoney_Load(object sender, EventArgs e)
        {
            try
            {
                this.lblClose.Visible = true;
                this.lblOK.Visible = false;
                sum = 0;
                #region 纸币器开始接收纸币模块
                //打开验钞 等待纸币进入
                this.timer1.Start();
            }
            catch (Exception ex)
            {

                MyMsg.MsgInfo(ex.Message);
            }
                #endregion
        }


        private void timer1_Tick(object sender, EventArgs e)
        {

            sum = 100;
            this.icMsg1.timer1.Stop();
            this.lblClose.Visible = false;
            this.lblOK.Location = new Point(568, 182);
            this.lblOK.Visible = true;
            this.label1.Text = string.Format("已读入金额：{0}元", sum);
            lblOK.Enabled = true;
            lblOK.Visible = true;

        }

        private void FrmInMoney_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.timer1.Stop();
            this.icMsg1.timer1.Stop();
        }
        private void backgroundWorker2_DoWork(object sender, DoWorkEventArgs e)
        {
            this.LableEnable(lblOK, true);
            this.LableVisable(label2, false);

        }

        private void backgroundWorker2_RunWorkerCompleted(object sender, RunWorkerCompletedEventArgs e)
        {
            this.LableEnable(lblOK, true);
            this.LableVisable(label2, false);
            this.DialogResult = DialogResult.OK;
        }


        #region 线程提示区
        private delegate void DLableEnable(Label lv, bool isenable);
        //Lable Enable设置
        void LableEnable(Label lv, bool isenable)
        {
            if (!lv.InvokeRequired)
            {
                lv.Enabled = isenable;
            }
            else
            {
                // 多线程调用时，通过主线程去访问
                DLableEnable de = LableEnable;
                this.Invoke(de, lv, isenable);
            }
        }
        //Lable Visable设置
        private delegate void DLableVisable(Label lv, bool isvisable);
        void LableVisable(Label lv, bool isvisable)
        {
            if (!lv.InvokeRequired)
            {
                lv.Visible = isvisable;
            }
            else
            {
                DLableVisable de = LableVisable;
                this.Invoke(de, lv, isvisable);
            }
        }
        #endregion

        private void backgroundWorker1_DoWork(object sender, DoWorkEventArgs e)
        {
            //axTTDriverMgr1.WriteToFile(Application.StartupPath + "\\LogFile\\money.log", "【" + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "】诊疗号【" + FrmMain.patientInfoData.Tables[0].Rows[0]["DIAGNOSEID"].ToString() + "】充值：" + iMoney + "元");
            //sum = 100;
            //this.icMsg1.timer1.Stop();
            //this.lblClose.Visible = false;
            //this.lblOK.Location = new Point(568, 182);
            //this.lblOK.Visible = true;
            //this.label1.Text = string.Format("已读入金额：{0}元", sum);
            //lblOK.Enabled = true;
            //lblOK.Visible = true;


        }
    }
}
